#define  _CRT_SECURE_NO_WARNINGS

#include "string.h"

namespace yjz
{
	void test_string1()
	{
		string s1;
		string s2("hello world");
		cout << s1.c_str() << endl;
		cout << s2.c_str() << endl;
		for (size_t i = 0; i < s2.size(); i++)
		{
			cout << s2[i] << " ";
		}
		cout << endl;

		string s3("hello world");
		string::iterator it = s3.begin();
		while (it != s3.end())
		{
			cout << *it << " ";
			++it;
		}
		cout << endl;
	}

	void test_string2()
	{
		string s1("hello world");
		s1.push_back('#');
		cout << s1.c_str() << endl;
		s1.append("Are you ok?");
		cout << s1.c_str() << endl;
		s1 += '%';
		cout << s1.c_str() << endl;
		s1 += "Are you ok?";
		cout << s1.c_str() << endl;
		s1.insert(1, '&');
		s1.insert(0, '*');
		cout << s1.c_str() << endl;
		s1.insert(6, "Are you ok?");
		cout << s1.c_str() << endl;
		s1.erase(1, 5);
		cout << s1.c_str() << endl;
	}

	void test_string3()
	{
		string s("hello world");
		size_t pos = s.find('l');
		string suffix = s.substr(pos, 6);
		cout << suffix.c_str() << endl;
		string s1("hello world");
		string s2 = s1;
		cout << s2.c_str() << endl;
		string s3("Are you ok?");
		s1 = s3;
		cout << s1.c_str() << endl;
	}

	void test_string4()
	{
		string s1("hello world");
		string s2;
		s2 = s1;
		cout << s1 << endl;
		cout << s2 << endl;
	}
}

int main()
{
	yjz::test_string4();
	return 0;
}